<?php
include_once dirname(__FILE__).'/lib/Soul/Util/Random.php';
session_start();
$str = Soul_Util_Random::randomCharacters(4);
$_SESSION['validatecode'] = $str;
$width = 160;
$height = 50;
$fontname = dirname(__FILE__).'/courbi.ttf';
@header("Content-Type:image/png");
$im = imagecreate(160, 50);
$back = imagecolorallocate($im, 0xFF, 0xFF, 0xFF);
$pix = imagecolorallocate($im, 187, 230, 247);
$fontcolor = imagecolorallocate($im, 41, 200, 238);
mt_srand();
for ($i = 0; $i < 1000; $i++) {
    imagesetpixel($im, mt_rand(0, $width), mt_rand(0, $height), $pix);
}
//imagestring($im, 20, 7, 5, $str, $font);
for($i = 0; $i < strlen($str); $i++){
    imagettftext($im, 32, mt_rand(-20, 20), 25 * ($i + 1), 38, $fontcolor, $fontname, $str[$i]);
}
imagerectangle($im, 0, 0, $width - 1, $height - 1, $fontcolor);
imagepng($im);
imagedestroy($im);